package com.view.speelveld;


import java.util.Observable;
import java.util.Observer;

import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.project_speelveld.R;
import com.model.speelveld.GameModel;

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public class Statusbar extends LinearLayout implements Observer{
	private GameModel gameModel ;
	private TextView tvLevel;
	private TextView tvWave ;
	private TextView tvKills;
	private TextView tvMoney;
	private TextView tvScore;
	private TextView tvLife;
	
	public Statusbar(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
		init();
	}

	public Statusbar(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
		init();
	}
	
	public Statusbar(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		// TODO Auto-generated constructor stub
		init();
	}

	private void init()
	{
		LayoutInflater inflater = (LayoutInflater)this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		inflater.inflate(R.layout.statusbar, this);
		
		tvLevel = (TextView) findViewById(R.id.txtLevel);
		tvWave = (TextView) findViewById(R.id.txtWave);
		tvKills = (TextView) findViewById(R.id.txtKills);
		tvLife = (TextView) findViewById(R.id.txtLives);
		tvMoney = (TextView) findViewById(R.id.txtMoney);
		tvScore = (TextView) findViewById(R.id.txtScore);
	}

	@Override
	public void update(Observable observable, Object data) 
	{
		setTextViewValues();
		
	}
	public void setGameModel(GameModel gameModel)
	{
		this.gameModel = gameModel;
		gameModel.addObserver(this);
		setTextViewValues();
		
	}
	public void setTextViewValues()
	{
		if(this.gameModel != null && tvLevel != null)
		{
			tvLevel.setText(getContext().getString(R.string.txtLevel) + gameModel.getLevel());
			tvKills.setText(getContext().getString(R.string.txtKills) + gameModel.getEnemiesKilled());
			tvLife.setText(getContext().getString(R.string.txtLives) + gameModel.getLives());
			tvMoney.setText(getContext().getString(R.string.txtMoney) + gameModel.getMoney());
			tvScore.setText(getContext().getString(R.string.txtScore) + gameModel.getScore());
			tvWave.setText(getContext().getString(R.string.txtWave) + gameModel.getWaveNumber());	
		}
	}
	
}
